package chapter03

/**
 * author: yuhui
 * descriptions: 冒泡排序
 * date: 2025 - 02 - 12 9:48 上午
 */
object MaopaoSort {
  def main(args: Array[String]) {
    val score: Array[Int] = Array(67, 55, 75, 87, 89, 70, 99, 10)
    var i: Int = 0
    while (i < score.length - 1) {
      {
        //最多做n-1趟排序
        var j: Int = 0
        while (j < score.length - i - 1) {
          {
            //对当前无序区间score[0......length-i-1]进行排序(j的范围很关键，这个范围是在逐步缩小的)
            if (score(j) < score(j + 1)) {
              //把小的值交换到后面
              val temp: Int = score(j)
              score(j) = score(j + 1)
              score(j + 1) = temp
            }
          }
          {
            j += 1;
            j - 1
          }
        }
        System.out.print("第" + (i + 1) + "次排序结果：")
        var a: Int = 0
        while (a < score.length) {
          {
            System.out.print(score(a) + "\t")
          }
          {
            a += 1;
            a - 1
          }
        }
        System.out.println("")
      }
      {
        i += 1;
        i - 1
      }
    }
    System.out.print("最终排序结果：")
    var a: Int = 0
    while (a < score.length) {
      {
        System.out.print(score(a) + "\t")
      }
      {
        a += 1;
        a - 1
      }
    }
  }
}